/*********************************************************/
/*
	functor for dynamic binding
	TEMPLATE_ARGS = 
	FUNCTION_ARGS = 
	FUNCTION_PARA = 
*/
template<typename ClassType, typename Ret  >
class functor<Ret(), dynamic_bind, ClassType>
{
private:
	struct FunctionHolderBase
	{
		virtual Ret operator()() const = 0;
		virtual ~FunctionHolderBase(){};
        virtual bool callable() const = 0;
	};


	template<typename ClassPointerType, typename Function>
	struct FunctionHolder : public FunctionHolderBase
	{
		ClassPointerType pObj_;
		Function func_;

		FunctionHolder(ClassPointerType pObj, const Function& func)
			: pObj_(pObj), func_(func){}

        bool callable() const
        {
            return bool(pObj_);
        }

		Ret operator()() const
		{
			return (pObj_->*func_)();
		}
	};

	template<typename Function>
	struct FunctionHolder<ClassStub, Function> : public FunctionHolderBase
	{
		Function func_;

		FunctionHolder(Function func):func_(func){}

        bool callable() const
        {
            return bool(func_);
        }

		Ret operator()() const
		{
			return (func_)();
		}
	};

	typedef acapella::shared_ptr<const FunctionHolderBase> FunctionHolderPtr;
	typedef FunctionHolderPtr HolderType;

public:
	typedef Ret(*FunctionType)();
	typedef functor<Ret(), dynamic_bind, ClassType> functor_type;
	typedef functor_list<Ret(), dynamic_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor(){};

	~functor(){};

	functor(const functor& func)
	{
		m_hs = func.m_hs;
	} 

	functor(FunctionType func)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassStub, FunctionType>(func));
	} 

	template <typename ClassPointerType, typename MemFun>
	functor(ClassPointerType pObj, MemFun mFun)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassPointerType, MemFun>(pObj, mFun));
	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}
		m_hs = functor_.m_hs;
		return *this;
	}

	void clear()
	{
		m_hs = FunctionHolderPtr(0);
	}
	
	bool callable() const
	{
        if (m_hs == 0)
        {
            return false;
        }
		return m_hs->callable();
	}
	
	Ret operator()() const
	{
        ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (*m_hs)();
	}

private:

	HolderType  m_hs;
};


/*
	functor for static member function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = 
	FUNCTION_ARGS = 
	FUNCTION_PARA = 
*/
template<typename ClassType, typename Ret  >
class functor<Ret(), static_bind, ClassType>
{
private:
	typedef Ret(ClassType::*MemberFunctionType)();
	typedef typename traits::type_traits<ClassType>::pointer_type ClassPoinerType;

public:
	typedef functor<Ret(), static_bind, ClassType> functor_type;
	typedef functor_list<Ret(), static_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor():pObj_(0), func_(0){};
	~functor(){};

	functor(ClassPoinerType pObj, MemberFunctionType mFun)
		:pObj_(pObj), func_(mFun)
	{}

	functor(const functor& functor_)
		:pObj_(functor_.pObj_), func_(functor_.func_)
	{

	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		pObj_ = functor_.pObj_;
		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		pObj_ = 0;
	}

	bool callable() const
	{
		return pObj_ != 0;
	}

	inline Ret operator()() const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (pObj_->*func_)();
	}

private:
	ClassPoinerType pObj_;
	MemberFunctionType func_;
};


/*
	functor for static function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = 
	FUNCTION_ARGS = 
	FUNCTION_PARA = 
*/
template<typename Ret  >
class functor<Ret(), static_bind, ClassStub>
{
private:
	typedef Ret(*FunctionType)();

public:
	typedef functor<Ret(), static_bind, ClassStub> functor_type;
	typedef functor_list<Ret(), static_bind, ClassStub> functor_list_type;
	typedef Ret return_type;

	functor():func_(0){};
	~functor(){};

	functor(const functor& functor_)
		:func_(functor_.func_)
	{

	}

	functor(FunctionType mFun)
		:func_(mFun)
	{}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		func_ = 0;
	}

	bool callable() const
	{
		return func_ != 0;
	}

	inline Ret operator()() const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (func_)();
	}

private:
	FunctionType func_;
};



/*
	functor_list
	TEMPLATE_ARGS = 
	FUNCTION_ARGS = 
	FUNCTION_PARA = 
*/
template<typename BindType, typename ClassType, typename Ret  >
class functor_list<Ret(), BindType, ClassType>
{
public:
	typedef functor<Ret(), BindType, ClassType> functor_type;
	typedef functor_list<Ret(), BindType, ClassType> functor_list_type;
	typedef Ret return_type;
	   
	functor_list()
    {
    }

	~functor_list()
    {
    }
	   
	functor_list(const functor_list& del)
		:m_hs(del.m_hs)
	{
	}

	functor_list(const functor_type& del)
	{
		m_hs.push_back(del);
	}

	functor_list& operator+(const functor_list& rhs)
	{
		m_hs.insert(m_hs.end(), rhs.m_hs.begin(), rhs.m_hs.end());
		return *this;
	}

	functor_list& operator+(const functor_type& rhs)
	{
		m_hs.push_back(rhs);
		return *this;
	}

	functor_list& operator+=(const functor_list& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	functor_list& operator+=(const functor_type& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	_uint32_ size() const
	{
		return m_hs.size();
	}

	void clear()
	{
		m_hs.clear();
	}

	Ret operator()() const
	{
		for (HolderIterator it = m_hs.begin();
			it != m_hs.end() - 1;
			++it)
		{
			(*it)();
		}
		return (*(m_hs.end() - 1))();
	}


private:
	typedef std::vector<functor_type> HolderType;
	typedef typename HolderType::const_iterator  HolderIterator;

	HolderType  m_hs;
};


/*
	functor_type
	TEMPLATE_ARGS = 
*/
template<typename BindType, typename RtVal, typename ClassType >
struct functor_type<RtVal (ClassType::*)(), BindType>
{
	typedef functor<RtVal (), BindType, ClassType> type;
	typedef functor_list<RtVal (), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal >
struct functor_type<RtVal (*)(), BindType>
{
	typedef functor<RtVal (), BindType, ClassStub> type;
	typedef functor_list<RtVal (), BindType, ClassStub> list_type;
};

/*********************************************************/





/*********************************************************/
/*
	functor for dynamic binding
	TEMPLATE_ARGS = , typename T0
	FUNCTION_ARGS = T0 t0
	FUNCTION_PARA = t0
*/
template<typename ClassType, typename Ret , typename T0 >
class functor<Ret(T0 t0), dynamic_bind, ClassType>
{
private:
	struct FunctionHolderBase
	{
		virtual Ret operator()(T0 t0) const = 0;
		virtual ~FunctionHolderBase(){};
        virtual bool callable() const = 0;
	};


	template<typename ClassPointerType, typename Function>
	struct FunctionHolder : public FunctionHolderBase
	{
		ClassPointerType pObj_;
		Function func_;

		FunctionHolder(ClassPointerType pObj, const Function& func)
			: pObj_(pObj), func_(func){}

        bool callable() const
        {
            return bool(pObj_);
        }

		Ret operator()(T0 t0) const
		{
			return (pObj_->*func_)(t0);
		}
	};

	template<typename Function>
	struct FunctionHolder<ClassStub, Function> : public FunctionHolderBase
	{
		Function func_;

		FunctionHolder(Function func):func_(func){}

        bool callable() const
        {
            return bool(func_);
        }

		Ret operator()(T0 t0) const
		{
			return (func_)(t0);
		}
	};

	typedef acapella::shared_ptr<const FunctionHolderBase> FunctionHolderPtr;
	typedef FunctionHolderPtr HolderType;

public:
	typedef Ret(*FunctionType)(T0 t0);
	typedef functor<Ret(T0 t0), dynamic_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0), dynamic_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor(){};

	~functor(){};

	functor(const functor& func)
	{
		m_hs = func.m_hs;
	} 

	functor(FunctionType func)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassStub, FunctionType>(func));
	} 

	template <typename ClassPointerType, typename MemFun>
	functor(ClassPointerType pObj, MemFun mFun)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassPointerType, MemFun>(pObj, mFun));
	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}
		m_hs = functor_.m_hs;
		return *this;
	}

	void clear()
	{
		m_hs = FunctionHolderPtr(0);
	}
	
	bool callable() const
	{
        if (m_hs == 0)
        {
            return false;
        }
		return m_hs->callable();
	}
	
	Ret operator()(T0 t0) const
	{
        ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (*m_hs)(t0);
	}

private:

	HolderType  m_hs;
};


/*
	functor for static member function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0
	FUNCTION_ARGS = T0 t0
	FUNCTION_PARA = t0
*/
template<typename ClassType, typename Ret , typename T0 >
class functor<Ret(T0 t0), static_bind, ClassType>
{
private:
	typedef Ret(ClassType::*MemberFunctionType)(T0 t0);
	typedef typename traits::type_traits<ClassType>::pointer_type ClassPoinerType;

public:
	typedef functor<Ret(T0 t0), static_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0), static_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor():pObj_(0), func_(0){};
	~functor(){};

	functor(ClassPoinerType pObj, MemberFunctionType mFun)
		:pObj_(pObj), func_(mFun)
	{}

	functor(const functor& functor_)
		:pObj_(functor_.pObj_), func_(functor_.func_)
	{

	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		pObj_ = functor_.pObj_;
		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		pObj_ = 0;
	}

	bool callable() const
	{
		return pObj_ != 0;
	}

	inline Ret operator()(T0 t0) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (pObj_->*func_)(t0);
	}

private:
	ClassPoinerType pObj_;
	MemberFunctionType func_;
};


/*
	functor for static function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0
	FUNCTION_ARGS = T0 t0
	FUNCTION_PARA = t0
*/
template<typename Ret , typename T0 >
class functor<Ret(T0 t0), static_bind, ClassStub>
{
private:
	typedef Ret(*FunctionType)(T0 t0);

public:
	typedef functor<Ret(T0 t0), static_bind, ClassStub> functor_type;
	typedef functor_list<Ret(T0 t0), static_bind, ClassStub> functor_list_type;
	typedef Ret return_type;

	functor():func_(0){};
	~functor(){};

	functor(const functor& functor_)
		:func_(functor_.func_)
	{

	}

	functor(FunctionType mFun)
		:func_(mFun)
	{}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		func_ = 0;
	}

	bool callable() const
	{
		return func_ != 0;
	}

	inline Ret operator()(T0 t0) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (func_)(t0);
	}

private:
	FunctionType func_;
};



/*
	functor_list
	TEMPLATE_ARGS = , typename T0
	FUNCTION_ARGS = T0 t0
	FUNCTION_PARA = t0
*/
template<typename BindType, typename ClassType, typename Ret , typename T0 >
class functor_list<Ret(T0 t0), BindType, ClassType>
{
public:
	typedef functor<Ret(T0 t0), BindType, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0), BindType, ClassType> functor_list_type;
	typedef Ret return_type;
	   
	functor_list()
    {
    }

	~functor_list()
    {
    }
	   
	functor_list(const functor_list& del)
		:m_hs(del.m_hs)
	{
	}

	functor_list(const functor_type& del)
	{
		m_hs.push_back(del);
	}

	functor_list& operator+(const functor_list& rhs)
	{
		m_hs.insert(m_hs.end(), rhs.m_hs.begin(), rhs.m_hs.end());
		return *this;
	}

	functor_list& operator+(const functor_type& rhs)
	{
		m_hs.push_back(rhs);
		return *this;
	}

	functor_list& operator+=(const functor_list& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	functor_list& operator+=(const functor_type& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	_uint32_ size() const
	{
		return m_hs.size();
	}

	void clear()
	{
		m_hs.clear();
	}

	Ret operator()(T0 t0) const
	{
		for (HolderIterator it = m_hs.begin();
			it != m_hs.end() - 1;
			++it)
		{
			(*it)(t0);
		}
		return (*(m_hs.end() - 1))(t0);
	}


private:
	typedef std::vector<functor_type> HolderType;
	typedef typename HolderType::const_iterator  HolderIterator;

	HolderType  m_hs;
};


/*
	functor_type
	TEMPLATE_ARGS = , typename T0
*/
template<typename BindType, typename RtVal, typename ClassType , typename T0>
struct functor_type<RtVal (ClassType::*)(T0 t0), BindType>
{
	typedef functor<RtVal (T0 t0), BindType, ClassType> type;
	typedef functor_list<RtVal (T0 t0), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal , typename T0>
struct functor_type<RtVal (*)(T0 t0), BindType>
{
	typedef functor<RtVal (T0 t0), BindType, ClassStub> type;
	typedef functor_list<RtVal (T0 t0), BindType, ClassStub> list_type;
};

/*********************************************************/





/*********************************************************/
/*
	functor for dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1
	FUNCTION_ARGS = T0 t0, T1 t1
	FUNCTION_PARA = t0, t1
*/
template<typename ClassType, typename Ret , typename T0, typename T1 >
class functor<Ret(T0 t0, T1 t1), dynamic_bind, ClassType>
{
private:
	struct FunctionHolderBase
	{
		virtual Ret operator()(T0 t0, T1 t1) const = 0;
		virtual ~FunctionHolderBase(){};
        virtual bool callable() const = 0;
	};


	template<typename ClassPointerType, typename Function>
	struct FunctionHolder : public FunctionHolderBase
	{
		ClassPointerType pObj_;
		Function func_;

		FunctionHolder(ClassPointerType pObj, const Function& func)
			: pObj_(pObj), func_(func){}

        bool callable() const
        {
            return bool(pObj_);
        }

		Ret operator()(T0 t0, T1 t1) const
		{
			return (pObj_->*func_)(t0, t1);
		}
	};

	template<typename Function>
	struct FunctionHolder<ClassStub, Function> : public FunctionHolderBase
	{
		Function func_;

		FunctionHolder(Function func):func_(func){}

        bool callable() const
        {
            return bool(func_);
        }

		Ret operator()(T0 t0, T1 t1) const
		{
			return (func_)(t0, t1);
		}
	};

	typedef acapella::shared_ptr<const FunctionHolderBase> FunctionHolderPtr;
	typedef FunctionHolderPtr HolderType;

public:
	typedef Ret(*FunctionType)(T0 t0, T1 t1);
	typedef functor<Ret(T0 t0, T1 t1), dynamic_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1), dynamic_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor(){};

	~functor(){};

	functor(const functor& func)
	{
		m_hs = func.m_hs;
	} 

	functor(FunctionType func)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassStub, FunctionType>(func));
	} 

	template <typename ClassPointerType, typename MemFun>
	functor(ClassPointerType pObj, MemFun mFun)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassPointerType, MemFun>(pObj, mFun));
	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}
		m_hs = functor_.m_hs;
		return *this;
	}

	void clear()
	{
		m_hs = FunctionHolderPtr(0);
	}
	
	bool callable() const
	{
        if (m_hs == 0)
        {
            return false;
        }
		return m_hs->callable();
	}
	
	Ret operator()(T0 t0, T1 t1) const
	{
        ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (*m_hs)(t0, t1);
	}

private:

	HolderType  m_hs;
};


/*
	functor for static member function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1
	FUNCTION_ARGS = T0 t0, T1 t1
	FUNCTION_PARA = t0, t1
*/
template<typename ClassType, typename Ret , typename T0, typename T1 >
class functor<Ret(T0 t0, T1 t1), static_bind, ClassType>
{
private:
	typedef Ret(ClassType::*MemberFunctionType)(T0 t0, T1 t1);
	typedef typename traits::type_traits<ClassType>::pointer_type ClassPoinerType;

public:
	typedef functor<Ret(T0 t0, T1 t1), static_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1), static_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor():pObj_(0), func_(0){};
	~functor(){};

	functor(ClassPoinerType pObj, MemberFunctionType mFun)
		:pObj_(pObj), func_(mFun)
	{}

	functor(const functor& functor_)
		:pObj_(functor_.pObj_), func_(functor_.func_)
	{

	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		pObj_ = functor_.pObj_;
		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		pObj_ = 0;
	}

	bool callable() const
	{
		return pObj_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (pObj_->*func_)(t0, t1);
	}

private:
	ClassPoinerType pObj_;
	MemberFunctionType func_;
};


/*
	functor for static function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1
	FUNCTION_ARGS = T0 t0, T1 t1
	FUNCTION_PARA = t0, t1
*/
template<typename Ret , typename T0, typename T1 >
class functor<Ret(T0 t0, T1 t1), static_bind, ClassStub>
{
private:
	typedef Ret(*FunctionType)(T0 t0, T1 t1);

public:
	typedef functor<Ret(T0 t0, T1 t1), static_bind, ClassStub> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1), static_bind, ClassStub> functor_list_type;
	typedef Ret return_type;

	functor():func_(0){};
	~functor(){};

	functor(const functor& functor_)
		:func_(functor_.func_)
	{

	}

	functor(FunctionType mFun)
		:func_(mFun)
	{}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		func_ = 0;
	}

	bool callable() const
	{
		return func_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (func_)(t0, t1);
	}

private:
	FunctionType func_;
};



/*
	functor_list
	TEMPLATE_ARGS = , typename T0, typename T1
	FUNCTION_ARGS = T0 t0, T1 t1
	FUNCTION_PARA = t0, t1
*/
template<typename BindType, typename ClassType, typename Ret , typename T0, typename T1 >
class functor_list<Ret(T0 t0, T1 t1), BindType, ClassType>
{
public:
	typedef functor<Ret(T0 t0, T1 t1), BindType, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1), BindType, ClassType> functor_list_type;
	typedef Ret return_type;
	   
	functor_list()
    {
    }

	~functor_list()
    {
    }
	   
	functor_list(const functor_list& del)
		:m_hs(del.m_hs)
	{
	}

	functor_list(const functor_type& del)
	{
		m_hs.push_back(del);
	}

	functor_list& operator+(const functor_list& rhs)
	{
		m_hs.insert(m_hs.end(), rhs.m_hs.begin(), rhs.m_hs.end());
		return *this;
	}

	functor_list& operator+(const functor_type& rhs)
	{
		m_hs.push_back(rhs);
		return *this;
	}

	functor_list& operator+=(const functor_list& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	functor_list& operator+=(const functor_type& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	_uint32_ size() const
	{
		return m_hs.size();
	}

	void clear()
	{
		m_hs.clear();
	}

	Ret operator()(T0 t0, T1 t1) const
	{
		for (HolderIterator it = m_hs.begin();
			it != m_hs.end() - 1;
			++it)
		{
			(*it)(t0, t1);
		}
		return (*(m_hs.end() - 1))(t0, t1);
	}


private:
	typedef std::vector<functor_type> HolderType;
	typedef typename HolderType::const_iterator  HolderIterator;

	HolderType  m_hs;
};


/*
	functor_type
	TEMPLATE_ARGS = , typename T0, typename T1
*/
template<typename BindType, typename RtVal, typename ClassType , typename T0, typename T1>
struct functor_type<RtVal (ClassType::*)(T0 t0, T1 t1), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1), BindType, ClassType> type;
	typedef functor_list<RtVal (T0 t0, T1 t1), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal , typename T0, typename T1>
struct functor_type<RtVal (*)(T0 t0, T1 t1), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1), BindType, ClassStub> type;
	typedef functor_list<RtVal (T0 t0, T1 t1), BindType, ClassStub> list_type;
};

/*********************************************************/





/*********************************************************/
/*
	functor for dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2
	FUNCTION_PARA = t0, t1, t2
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2 >
class functor<Ret(T0 t0, T1 t1, T2 t2), dynamic_bind, ClassType>
{
private:
	struct FunctionHolderBase
	{
		virtual Ret operator()(T0 t0, T1 t1, T2 t2) const = 0;
		virtual ~FunctionHolderBase(){};
        virtual bool callable() const = 0;
	};


	template<typename ClassPointerType, typename Function>
	struct FunctionHolder : public FunctionHolderBase
	{
		ClassPointerType pObj_;
		Function func_;

		FunctionHolder(ClassPointerType pObj, const Function& func)
			: pObj_(pObj), func_(func){}

        bool callable() const
        {
            return bool(pObj_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2) const
		{
			return (pObj_->*func_)(t0, t1, t2);
		}
	};

	template<typename Function>
	struct FunctionHolder<ClassStub, Function> : public FunctionHolderBase
	{
		Function func_;

		FunctionHolder(Function func):func_(func){}

        bool callable() const
        {
            return bool(func_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2) const
		{
			return (func_)(t0, t1, t2);
		}
	};

	typedef acapella::shared_ptr<const FunctionHolderBase> FunctionHolderPtr;
	typedef FunctionHolderPtr HolderType;

public:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2);
	typedef functor<Ret(T0 t0, T1 t1, T2 t2), dynamic_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2), dynamic_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor(){};

	~functor(){};

	functor(const functor& func)
	{
		m_hs = func.m_hs;
	} 

	functor(FunctionType func)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassStub, FunctionType>(func));
	} 

	template <typename ClassPointerType, typename MemFun>
	functor(ClassPointerType pObj, MemFun mFun)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassPointerType, MemFun>(pObj, mFun));
	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}
		m_hs = functor_.m_hs;
		return *this;
	}

	void clear()
	{
		m_hs = FunctionHolderPtr(0);
	}
	
	bool callable() const
	{
        if (m_hs == 0)
        {
            return false;
        }
		return m_hs->callable();
	}
	
	Ret operator()(T0 t0, T1 t1, T2 t2) const
	{
        ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (*m_hs)(t0, t1, t2);
	}

private:

	HolderType  m_hs;
};


/*
	functor for static member function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2
	FUNCTION_PARA = t0, t1, t2
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2 >
class functor<Ret(T0 t0, T1 t1, T2 t2), static_bind, ClassType>
{
private:
	typedef Ret(ClassType::*MemberFunctionType)(T0 t0, T1 t1, T2 t2);
	typedef typename traits::type_traits<ClassType>::pointer_type ClassPoinerType;

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2), static_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2), static_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor():pObj_(0), func_(0){};
	~functor(){};

	functor(ClassPoinerType pObj, MemberFunctionType mFun)
		:pObj_(pObj), func_(mFun)
	{}

	functor(const functor& functor_)
		:pObj_(functor_.pObj_), func_(functor_.func_)
	{

	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		pObj_ = functor_.pObj_;
		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		pObj_ = 0;
	}

	bool callable() const
	{
		return pObj_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (pObj_->*func_)(t0, t1, t2);
	}

private:
	ClassPoinerType pObj_;
	MemberFunctionType func_;
};


/*
	functor for static function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2
	FUNCTION_PARA = t0, t1, t2
*/
template<typename Ret , typename T0, typename T1, typename T2 >
class functor<Ret(T0 t0, T1 t1, T2 t2), static_bind, ClassStub>
{
private:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2);

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2), static_bind, ClassStub> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2), static_bind, ClassStub> functor_list_type;
	typedef Ret return_type;

	functor():func_(0){};
	~functor(){};

	functor(const functor& functor_)
		:func_(functor_.func_)
	{

	}

	functor(FunctionType mFun)
		:func_(mFun)
	{}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		func_ = 0;
	}

	bool callable() const
	{
		return func_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (func_)(t0, t1, t2);
	}

private:
	FunctionType func_;
};



/*
	functor_list
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2
	FUNCTION_PARA = t0, t1, t2
*/
template<typename BindType, typename ClassType, typename Ret , typename T0, typename T1, typename T2 >
class functor_list<Ret(T0 t0, T1 t1, T2 t2), BindType, ClassType>
{
public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2), BindType, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2), BindType, ClassType> functor_list_type;
	typedef Ret return_type;
	   
	functor_list()
    {
    }

	~functor_list()
    {
    }
	   
	functor_list(const functor_list& del)
		:m_hs(del.m_hs)
	{
	}

	functor_list(const functor_type& del)
	{
		m_hs.push_back(del);
	}

	functor_list& operator+(const functor_list& rhs)
	{
		m_hs.insert(m_hs.end(), rhs.m_hs.begin(), rhs.m_hs.end());
		return *this;
	}

	functor_list& operator+(const functor_type& rhs)
	{
		m_hs.push_back(rhs);
		return *this;
	}

	functor_list& operator+=(const functor_list& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	functor_list& operator+=(const functor_type& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	_uint32_ size() const
	{
		return m_hs.size();
	}

	void clear()
	{
		m_hs.clear();
	}

	Ret operator()(T0 t0, T1 t1, T2 t2) const
	{
		for (HolderIterator it = m_hs.begin();
			it != m_hs.end() - 1;
			++it)
		{
			(*it)(t0, t1, t2);
		}
		return (*(m_hs.end() - 1))(t0, t1, t2);
	}


private:
	typedef std::vector<functor_type> HolderType;
	typedef typename HolderType::const_iterator  HolderIterator;

	HolderType  m_hs;
};


/*
	functor_type
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2
*/
template<typename BindType, typename RtVal, typename ClassType , typename T0, typename T1, typename T2>
struct functor_type<RtVal (ClassType::*)(T0 t0, T1 t1, T2 t2), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2), BindType, ClassType> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal , typename T0, typename T1, typename T2>
struct functor_type<RtVal (*)(T0 t0, T1 t1, T2 t2), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2), BindType, ClassStub> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2), BindType, ClassStub> list_type;
};

/*********************************************************/





/*********************************************************/
/*
	functor for dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3
	FUNCTION_PARA = t0, t1, t2, t3
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3), dynamic_bind, ClassType>
{
private:
	struct FunctionHolderBase
	{
		virtual Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3) const = 0;
		virtual ~FunctionHolderBase(){};
        virtual bool callable() const = 0;
	};


	template<typename ClassPointerType, typename Function>
	struct FunctionHolder : public FunctionHolderBase
	{
		ClassPointerType pObj_;
		Function func_;

		FunctionHolder(ClassPointerType pObj, const Function& func)
			: pObj_(pObj), func_(func){}

        bool callable() const
        {
            return bool(pObj_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3) const
		{
			return (pObj_->*func_)(t0, t1, t2, t3);
		}
	};

	template<typename Function>
	struct FunctionHolder<ClassStub, Function> : public FunctionHolderBase
	{
		Function func_;

		FunctionHolder(Function func):func_(func){}

        bool callable() const
        {
            return bool(func_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3) const
		{
			return (func_)(t0, t1, t2, t3);
		}
	};

	typedef acapella::shared_ptr<const FunctionHolderBase> FunctionHolderPtr;
	typedef FunctionHolderPtr HolderType;

public:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3);
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3), dynamic_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3), dynamic_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor(){};

	~functor(){};

	functor(const functor& func)
	{
		m_hs = func.m_hs;
	} 

	functor(FunctionType func)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassStub, FunctionType>(func));
	} 

	template <typename ClassPointerType, typename MemFun>
	functor(ClassPointerType pObj, MemFun mFun)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassPointerType, MemFun>(pObj, mFun));
	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}
		m_hs = functor_.m_hs;
		return *this;
	}

	void clear()
	{
		m_hs = FunctionHolderPtr(0);
	}
	
	bool callable() const
	{
        if (m_hs == 0)
        {
            return false;
        }
		return m_hs->callable();
	}
	
	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3) const
	{
        ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (*m_hs)(t0, t1, t2, t3);
	}

private:

	HolderType  m_hs;
};


/*
	functor for static member function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3
	FUNCTION_PARA = t0, t1, t2, t3
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3), static_bind, ClassType>
{
private:
	typedef Ret(ClassType::*MemberFunctionType)(T0 t0, T1 t1, T2 t2, T3 t3);
	typedef typename traits::type_traits<ClassType>::pointer_type ClassPoinerType;

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3), static_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3), static_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor():pObj_(0), func_(0){};
	~functor(){};

	functor(ClassPoinerType pObj, MemberFunctionType mFun)
		:pObj_(pObj), func_(mFun)
	{}

	functor(const functor& functor_)
		:pObj_(functor_.pObj_), func_(functor_.func_)
	{

	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		pObj_ = functor_.pObj_;
		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		pObj_ = 0;
	}

	bool callable() const
	{
		return pObj_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (pObj_->*func_)(t0, t1, t2, t3);
	}

private:
	ClassPoinerType pObj_;
	MemberFunctionType func_;
};


/*
	functor for static function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3
	FUNCTION_PARA = t0, t1, t2, t3
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3), static_bind, ClassStub>
{
private:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3);

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3), static_bind, ClassStub> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3), static_bind, ClassStub> functor_list_type;
	typedef Ret return_type;

	functor():func_(0){};
	~functor(){};

	functor(const functor& functor_)
		:func_(functor_.func_)
	{

	}

	functor(FunctionType mFun)
		:func_(mFun)
	{}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		func_ = 0;
	}

	bool callable() const
	{
		return func_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (func_)(t0, t1, t2, t3);
	}

private:
	FunctionType func_;
};



/*
	functor_list
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3
	FUNCTION_PARA = t0, t1, t2, t3
*/
template<typename BindType, typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3 >
class functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3), BindType, ClassType>
{
public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3), BindType, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3), BindType, ClassType> functor_list_type;
	typedef Ret return_type;
	   
	functor_list()
    {
    }

	~functor_list()
    {
    }
	   
	functor_list(const functor_list& del)
		:m_hs(del.m_hs)
	{
	}

	functor_list(const functor_type& del)
	{
		m_hs.push_back(del);
	}

	functor_list& operator+(const functor_list& rhs)
	{
		m_hs.insert(m_hs.end(), rhs.m_hs.begin(), rhs.m_hs.end());
		return *this;
	}

	functor_list& operator+(const functor_type& rhs)
	{
		m_hs.push_back(rhs);
		return *this;
	}

	functor_list& operator+=(const functor_list& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	functor_list& operator+=(const functor_type& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	_uint32_ size() const
	{
		return m_hs.size();
	}

	void clear()
	{
		m_hs.clear();
	}

	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3) const
	{
		for (HolderIterator it = m_hs.begin();
			it != m_hs.end() - 1;
			++it)
		{
			(*it)(t0, t1, t2, t3);
		}
		return (*(m_hs.end() - 1))(t0, t1, t2, t3);
	}


private:
	typedef std::vector<functor_type> HolderType;
	typedef typename HolderType::const_iterator  HolderIterator;

	HolderType  m_hs;
};


/*
	functor_type
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3
*/
template<typename BindType, typename RtVal, typename ClassType , typename T0, typename T1, typename T2, typename T3>
struct functor_type<RtVal (ClassType::*)(T0 t0, T1 t1, T2 t2, T3 t3), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3), BindType, ClassType> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal , typename T0, typename T1, typename T2, typename T3>
struct functor_type<RtVal (*)(T0 t0, T1 t1, T2 t2, T3 t3), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3), BindType, ClassStub> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3), BindType, ClassStub> list_type;
};

/*********************************************************/





/*********************************************************/
/*
	functor for dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4
	FUNCTION_PARA = t0, t1, t2, t3, t4
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), dynamic_bind, ClassType>
{
private:
	struct FunctionHolderBase
	{
		virtual Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) const = 0;
		virtual ~FunctionHolderBase(){};
        virtual bool callable() const = 0;
	};


	template<typename ClassPointerType, typename Function>
	struct FunctionHolder : public FunctionHolderBase
	{
		ClassPointerType pObj_;
		Function func_;

		FunctionHolder(ClassPointerType pObj, const Function& func)
			: pObj_(pObj), func_(func){}

        bool callable() const
        {
            return bool(pObj_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) const
		{
			return (pObj_->*func_)(t0, t1, t2, t3, t4);
		}
	};

	template<typename Function>
	struct FunctionHolder<ClassStub, Function> : public FunctionHolderBase
	{
		Function func_;

		FunctionHolder(Function func):func_(func){}

        bool callable() const
        {
            return bool(func_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) const
		{
			return (func_)(t0, t1, t2, t3, t4);
		}
	};

	typedef acapella::shared_ptr<const FunctionHolderBase> FunctionHolderPtr;
	typedef FunctionHolderPtr HolderType;

public:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4);
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), dynamic_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), dynamic_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor(){};

	~functor(){};

	functor(const functor& func)
	{
		m_hs = func.m_hs;
	} 

	functor(FunctionType func)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassStub, FunctionType>(func));
	} 

	template <typename ClassPointerType, typename MemFun>
	functor(ClassPointerType pObj, MemFun mFun)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassPointerType, MemFun>(pObj, mFun));
	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}
		m_hs = functor_.m_hs;
		return *this;
	}

	void clear()
	{
		m_hs = FunctionHolderPtr(0);
	}
	
	bool callable() const
	{
        if (m_hs == 0)
        {
            return false;
        }
		return m_hs->callable();
	}
	
	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) const
	{
        ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (*m_hs)(t0, t1, t2, t3, t4);
	}

private:

	HolderType  m_hs;
};


/*
	functor for static member function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4
	FUNCTION_PARA = t0, t1, t2, t3, t4
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), static_bind, ClassType>
{
private:
	typedef Ret(ClassType::*MemberFunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4);
	typedef typename traits::type_traits<ClassType>::pointer_type ClassPoinerType;

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), static_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), static_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor():pObj_(0), func_(0){};
	~functor(){};

	functor(ClassPoinerType pObj, MemberFunctionType mFun)
		:pObj_(pObj), func_(mFun)
	{}

	functor(const functor& functor_)
		:pObj_(functor_.pObj_), func_(functor_.func_)
	{

	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		pObj_ = functor_.pObj_;
		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		pObj_ = 0;
	}

	bool callable() const
	{
		return pObj_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (pObj_->*func_)(t0, t1, t2, t3, t4);
	}

private:
	ClassPoinerType pObj_;
	MemberFunctionType func_;
};


/*
	functor for static function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4
	FUNCTION_PARA = t0, t1, t2, t3, t4
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), static_bind, ClassStub>
{
private:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4);

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), static_bind, ClassStub> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), static_bind, ClassStub> functor_list_type;
	typedef Ret return_type;

	functor():func_(0){};
	~functor(){};

	functor(const functor& functor_)
		:func_(functor_.func_)
	{

	}

	functor(FunctionType mFun)
		:func_(mFun)
	{}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		func_ = 0;
	}

	bool callable() const
	{
		return func_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (func_)(t0, t1, t2, t3, t4);
	}

private:
	FunctionType func_;
};



/*
	functor_list
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4
	FUNCTION_PARA = t0, t1, t2, t3, t4
*/
template<typename BindType, typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4 >
class functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType, ClassType>
{
public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType, ClassType> functor_list_type;
	typedef Ret return_type;
	   
	functor_list()
    {
    }

	~functor_list()
    {
    }
	   
	functor_list(const functor_list& del)
		:m_hs(del.m_hs)
	{
	}

	functor_list(const functor_type& del)
	{
		m_hs.push_back(del);
	}

	functor_list& operator+(const functor_list& rhs)
	{
		m_hs.insert(m_hs.end(), rhs.m_hs.begin(), rhs.m_hs.end());
		return *this;
	}

	functor_list& operator+(const functor_type& rhs)
	{
		m_hs.push_back(rhs);
		return *this;
	}

	functor_list& operator+=(const functor_list& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	functor_list& operator+=(const functor_type& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	_uint32_ size() const
	{
		return m_hs.size();
	}

	void clear()
	{
		m_hs.clear();
	}

	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4) const
	{
		for (HolderIterator it = m_hs.begin();
			it != m_hs.end() - 1;
			++it)
		{
			(*it)(t0, t1, t2, t3, t4);
		}
		return (*(m_hs.end() - 1))(t0, t1, t2, t3, t4);
	}


private:
	typedef std::vector<functor_type> HolderType;
	typedef typename HolderType::const_iterator  HolderIterator;

	HolderType  m_hs;
};


/*
	functor_type
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4
*/
template<typename BindType, typename RtVal, typename ClassType , typename T0, typename T1, typename T2, typename T3, typename T4>
struct functor_type<RtVal (ClassType::*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType, ClassType> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal , typename T0, typename T1, typename T2, typename T3, typename T4>
struct functor_type<RtVal (*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType, ClassStub> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4), BindType, ClassStub> list_type;
};

/*********************************************************/





/*********************************************************/
/*
	functor for dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), dynamic_bind, ClassType>
{
private:
	struct FunctionHolderBase
	{
		virtual Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) const = 0;
		virtual ~FunctionHolderBase(){};
        virtual bool callable() const = 0;
	};


	template<typename ClassPointerType, typename Function>
	struct FunctionHolder : public FunctionHolderBase
	{
		ClassPointerType pObj_;
		Function func_;

		FunctionHolder(ClassPointerType pObj, const Function& func)
			: pObj_(pObj), func_(func){}

        bool callable() const
        {
            return bool(pObj_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) const
		{
			return (pObj_->*func_)(t0, t1, t2, t3, t4, t5);
		}
	};

	template<typename Function>
	struct FunctionHolder<ClassStub, Function> : public FunctionHolderBase
	{
		Function func_;

		FunctionHolder(Function func):func_(func){}

        bool callable() const
        {
            return bool(func_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) const
		{
			return (func_)(t0, t1, t2, t3, t4, t5);
		}
	};

	typedef acapella::shared_ptr<const FunctionHolderBase> FunctionHolderPtr;
	typedef FunctionHolderPtr HolderType;

public:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5);
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), dynamic_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), dynamic_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor(){};

	~functor(){};

	functor(const functor& func)
	{
		m_hs = func.m_hs;
	} 

	functor(FunctionType func)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassStub, FunctionType>(func));
	} 

	template <typename ClassPointerType, typename MemFun>
	functor(ClassPointerType pObj, MemFun mFun)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassPointerType, MemFun>(pObj, mFun));
	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}
		m_hs = functor_.m_hs;
		return *this;
	}

	void clear()
	{
		m_hs = FunctionHolderPtr(0);
	}
	
	bool callable() const
	{
        if (m_hs == 0)
        {
            return false;
        }
		return m_hs->callable();
	}
	
	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) const
	{
        ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (*m_hs)(t0, t1, t2, t3, t4, t5);
	}

private:

	HolderType  m_hs;
};


/*
	functor for static member function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), static_bind, ClassType>
{
private:
	typedef Ret(ClassType::*MemberFunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5);
	typedef typename traits::type_traits<ClassType>::pointer_type ClassPoinerType;

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), static_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), static_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor():pObj_(0), func_(0){};
	~functor(){};

	functor(ClassPoinerType pObj, MemberFunctionType mFun)
		:pObj_(pObj), func_(mFun)
	{}

	functor(const functor& functor_)
		:pObj_(functor_.pObj_), func_(functor_.func_)
	{

	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		pObj_ = functor_.pObj_;
		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		pObj_ = 0;
	}

	bool callable() const
	{
		return pObj_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (pObj_->*func_)(t0, t1, t2, t3, t4, t5);
	}

private:
	ClassPoinerType pObj_;
	MemberFunctionType func_;
};


/*
	functor for static function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), static_bind, ClassStub>
{
private:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5);

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), static_bind, ClassStub> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), static_bind, ClassStub> functor_list_type;
	typedef Ret return_type;

	functor():func_(0){};
	~functor(){};

	functor(const functor& functor_)
		:func_(functor_.func_)
	{

	}

	functor(FunctionType mFun)
		:func_(mFun)
	{}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		func_ = 0;
	}

	bool callable() const
	{
		return func_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (func_)(t0, t1, t2, t3, t4, t5);
	}

private:
	FunctionType func_;
};



/*
	functor_list
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5
*/
template<typename BindType, typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5 >
class functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType, ClassType>
{
public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType, ClassType> functor_list_type;
	typedef Ret return_type;
	   
	functor_list()
    {
    }

	~functor_list()
    {
    }
	   
	functor_list(const functor_list& del)
		:m_hs(del.m_hs)
	{
	}

	functor_list(const functor_type& del)
	{
		m_hs.push_back(del);
	}

	functor_list& operator+(const functor_list& rhs)
	{
		m_hs.insert(m_hs.end(), rhs.m_hs.begin(), rhs.m_hs.end());
		return *this;
	}

	functor_list& operator+(const functor_type& rhs)
	{
		m_hs.push_back(rhs);
		return *this;
	}

	functor_list& operator+=(const functor_list& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	functor_list& operator+=(const functor_type& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	_uint32_ size() const
	{
		return m_hs.size();
	}

	void clear()
	{
		m_hs.clear();
	}

	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5) const
	{
		for (HolderIterator it = m_hs.begin();
			it != m_hs.end() - 1;
			++it)
		{
			(*it)(t0, t1, t2, t3, t4, t5);
		}
		return (*(m_hs.end() - 1))(t0, t1, t2, t3, t4, t5);
	}


private:
	typedef std::vector<functor_type> HolderType;
	typedef typename HolderType::const_iterator  HolderIterator;

	HolderType  m_hs;
};


/*
	functor_type
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5
*/
template<typename BindType, typename RtVal, typename ClassType , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
struct functor_type<RtVal (ClassType::*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType, ClassType> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
struct functor_type<RtVal (*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType, ClassStub> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5), BindType, ClassStub> list_type;
};

/*********************************************************/





/*********************************************************/
/*
	functor for dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), dynamic_bind, ClassType>
{
private:
	struct FunctionHolderBase
	{
		virtual Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) const = 0;
		virtual ~FunctionHolderBase(){};
        virtual bool callable() const = 0;
	};


	template<typename ClassPointerType, typename Function>
	struct FunctionHolder : public FunctionHolderBase
	{
		ClassPointerType pObj_;
		Function func_;

		FunctionHolder(ClassPointerType pObj, const Function& func)
			: pObj_(pObj), func_(func){}

        bool callable() const
        {
            return bool(pObj_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) const
		{
			return (pObj_->*func_)(t0, t1, t2, t3, t4, t5, t6);
		}
	};

	template<typename Function>
	struct FunctionHolder<ClassStub, Function> : public FunctionHolderBase
	{
		Function func_;

		FunctionHolder(Function func):func_(func){}

        bool callable() const
        {
            return bool(func_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) const
		{
			return (func_)(t0, t1, t2, t3, t4, t5, t6);
		}
	};

	typedef acapella::shared_ptr<const FunctionHolderBase> FunctionHolderPtr;
	typedef FunctionHolderPtr HolderType;

public:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6);
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), dynamic_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), dynamic_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor(){};

	~functor(){};

	functor(const functor& func)
	{
		m_hs = func.m_hs;
	} 

	functor(FunctionType func)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassStub, FunctionType>(func));
	} 

	template <typename ClassPointerType, typename MemFun>
	functor(ClassPointerType pObj, MemFun mFun)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassPointerType, MemFun>(pObj, mFun));
	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}
		m_hs = functor_.m_hs;
		return *this;
	}

	void clear()
	{
		m_hs = FunctionHolderPtr(0);
	}
	
	bool callable() const
	{
        if (m_hs == 0)
        {
            return false;
        }
		return m_hs->callable();
	}
	
	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) const
	{
        ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (*m_hs)(t0, t1, t2, t3, t4, t5, t6);
	}

private:

	HolderType  m_hs;
};


/*
	functor for static member function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), static_bind, ClassType>
{
private:
	typedef Ret(ClassType::*MemberFunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6);
	typedef typename traits::type_traits<ClassType>::pointer_type ClassPoinerType;

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), static_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), static_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor():pObj_(0), func_(0){};
	~functor(){};

	functor(ClassPoinerType pObj, MemberFunctionType mFun)
		:pObj_(pObj), func_(mFun)
	{}

	functor(const functor& functor_)
		:pObj_(functor_.pObj_), func_(functor_.func_)
	{

	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		pObj_ = functor_.pObj_;
		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		pObj_ = 0;
	}

	bool callable() const
	{
		return pObj_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (pObj_->*func_)(t0, t1, t2, t3, t4, t5, t6);
	}

private:
	ClassPoinerType pObj_;
	MemberFunctionType func_;
};


/*
	functor for static function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), static_bind, ClassStub>
{
private:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6);

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), static_bind, ClassStub> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), static_bind, ClassStub> functor_list_type;
	typedef Ret return_type;

	functor():func_(0){};
	~functor(){};

	functor(const functor& functor_)
		:func_(functor_.func_)
	{

	}

	functor(FunctionType mFun)
		:func_(mFun)
	{}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		func_ = 0;
	}

	bool callable() const
	{
		return func_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (func_)(t0, t1, t2, t3, t4, t5, t6);
	}

private:
	FunctionType func_;
};



/*
	functor_list
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6
*/
template<typename BindType, typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6 >
class functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType, ClassType>
{
public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType, ClassType> functor_list_type;
	typedef Ret return_type;
	   
	functor_list()
    {
    }

	~functor_list()
    {
    }
	   
	functor_list(const functor_list& del)
		:m_hs(del.m_hs)
	{
	}

	functor_list(const functor_type& del)
	{
		m_hs.push_back(del);
	}

	functor_list& operator+(const functor_list& rhs)
	{
		m_hs.insert(m_hs.end(), rhs.m_hs.begin(), rhs.m_hs.end());
		return *this;
	}

	functor_list& operator+(const functor_type& rhs)
	{
		m_hs.push_back(rhs);
		return *this;
	}

	functor_list& operator+=(const functor_list& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	functor_list& operator+=(const functor_type& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	_uint32_ size() const
	{
		return m_hs.size();
	}

	void clear()
	{
		m_hs.clear();
	}

	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6) const
	{
		for (HolderIterator it = m_hs.begin();
			it != m_hs.end() - 1;
			++it)
		{
			(*it)(t0, t1, t2, t3, t4, t5, t6);
		}
		return (*(m_hs.end() - 1))(t0, t1, t2, t3, t4, t5, t6);
	}


private:
	typedef std::vector<functor_type> HolderType;
	typedef typename HolderType::const_iterator  HolderIterator;

	HolderType  m_hs;
};


/*
	functor_type
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6
*/
template<typename BindType, typename RtVal, typename ClassType , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct functor_type<RtVal (ClassType::*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType, ClassType> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct functor_type<RtVal (*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType, ClassStub> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6), BindType, ClassStub> list_type;
};

/*********************************************************/





/*********************************************************/
/*
	functor for dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), dynamic_bind, ClassType>
{
private:
	struct FunctionHolderBase
	{
		virtual Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) const = 0;
		virtual ~FunctionHolderBase(){};
        virtual bool callable() const = 0;
	};


	template<typename ClassPointerType, typename Function>
	struct FunctionHolder : public FunctionHolderBase
	{
		ClassPointerType pObj_;
		Function func_;

		FunctionHolder(ClassPointerType pObj, const Function& func)
			: pObj_(pObj), func_(func){}

        bool callable() const
        {
            return bool(pObj_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) const
		{
			return (pObj_->*func_)(t0, t1, t2, t3, t4, t5, t6, t7);
		}
	};

	template<typename Function>
	struct FunctionHolder<ClassStub, Function> : public FunctionHolderBase
	{
		Function func_;

		FunctionHolder(Function func):func_(func){}

        bool callable() const
        {
            return bool(func_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) const
		{
			return (func_)(t0, t1, t2, t3, t4, t5, t6, t7);
		}
	};

	typedef acapella::shared_ptr<const FunctionHolderBase> FunctionHolderPtr;
	typedef FunctionHolderPtr HolderType;

public:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7);
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), dynamic_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), dynamic_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor(){};

	~functor(){};

	functor(const functor& func)
	{
		m_hs = func.m_hs;
	} 

	functor(FunctionType func)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassStub, FunctionType>(func));
	} 

	template <typename ClassPointerType, typename MemFun>
	functor(ClassPointerType pObj, MemFun mFun)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassPointerType, MemFun>(pObj, mFun));
	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}
		m_hs = functor_.m_hs;
		return *this;
	}

	void clear()
	{
		m_hs = FunctionHolderPtr(0);
	}
	
	bool callable() const
	{
        if (m_hs == 0)
        {
            return false;
        }
		return m_hs->callable();
	}
	
	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) const
	{
        ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (*m_hs)(t0, t1, t2, t3, t4, t5, t6, t7);
	}

private:

	HolderType  m_hs;
};


/*
	functor for static member function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), static_bind, ClassType>
{
private:
	typedef Ret(ClassType::*MemberFunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7);
	typedef typename traits::type_traits<ClassType>::pointer_type ClassPoinerType;

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), static_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), static_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor():pObj_(0), func_(0){};
	~functor(){};

	functor(ClassPoinerType pObj, MemberFunctionType mFun)
		:pObj_(pObj), func_(mFun)
	{}

	functor(const functor& functor_)
		:pObj_(functor_.pObj_), func_(functor_.func_)
	{

	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		pObj_ = functor_.pObj_;
		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		pObj_ = 0;
	}

	bool callable() const
	{
		return pObj_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (pObj_->*func_)(t0, t1, t2, t3, t4, t5, t6, t7);
	}

private:
	ClassPoinerType pObj_;
	MemberFunctionType func_;
};


/*
	functor for static function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), static_bind, ClassStub>
{
private:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7);

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), static_bind, ClassStub> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), static_bind, ClassStub> functor_list_type;
	typedef Ret return_type;

	functor():func_(0){};
	~functor(){};

	functor(const functor& functor_)
		:func_(functor_.func_)
	{

	}

	functor(FunctionType mFun)
		:func_(mFun)
	{}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		func_ = 0;
	}

	bool callable() const
	{
		return func_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (func_)(t0, t1, t2, t3, t4, t5, t6, t7);
	}

private:
	FunctionType func_;
};



/*
	functor_list
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7
*/
template<typename BindType, typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7 >
class functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType, ClassType>
{
public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType, ClassType> functor_list_type;
	typedef Ret return_type;
	   
	functor_list()
    {
    }

	~functor_list()
    {
    }
	   
	functor_list(const functor_list& del)
		:m_hs(del.m_hs)
	{
	}

	functor_list(const functor_type& del)
	{
		m_hs.push_back(del);
	}

	functor_list& operator+(const functor_list& rhs)
	{
		m_hs.insert(m_hs.end(), rhs.m_hs.begin(), rhs.m_hs.end());
		return *this;
	}

	functor_list& operator+(const functor_type& rhs)
	{
		m_hs.push_back(rhs);
		return *this;
	}

	functor_list& operator+=(const functor_list& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	functor_list& operator+=(const functor_type& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	_uint32_ size() const
	{
		return m_hs.size();
	}

	void clear()
	{
		m_hs.clear();
	}

	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7) const
	{
		for (HolderIterator it = m_hs.begin();
			it != m_hs.end() - 1;
			++it)
		{
			(*it)(t0, t1, t2, t3, t4, t5, t6, t7);
		}
		return (*(m_hs.end() - 1))(t0, t1, t2, t3, t4, t5, t6, t7);
	}


private:
	typedef std::vector<functor_type> HolderType;
	typedef typename HolderType::const_iterator  HolderIterator;

	HolderType  m_hs;
};


/*
	functor_type
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7
*/
template<typename BindType, typename RtVal, typename ClassType , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct functor_type<RtVal (ClassType::*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType, ClassType> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct functor_type<RtVal (*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType, ClassStub> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7), BindType, ClassStub> list_type;
};

/*********************************************************/





/*********************************************************/
/*
	functor for dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7, t8
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), dynamic_bind, ClassType>
{
private:
	struct FunctionHolderBase
	{
		virtual Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) const = 0;
		virtual ~FunctionHolderBase(){};
        virtual bool callable() const = 0;
	};


	template<typename ClassPointerType, typename Function>
	struct FunctionHolder : public FunctionHolderBase
	{
		ClassPointerType pObj_;
		Function func_;

		FunctionHolder(ClassPointerType pObj, const Function& func)
			: pObj_(pObj), func_(func){}

        bool callable() const
        {
            return bool(pObj_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) const
		{
			return (pObj_->*func_)(t0, t1, t2, t3, t4, t5, t6, t7, t8);
		}
	};

	template<typename Function>
	struct FunctionHolder<ClassStub, Function> : public FunctionHolderBase
	{
		Function func_;

		FunctionHolder(Function func):func_(func){}

        bool callable() const
        {
            return bool(func_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) const
		{
			return (func_)(t0, t1, t2, t3, t4, t5, t6, t7, t8);
		}
	};

	typedef acapella::shared_ptr<const FunctionHolderBase> FunctionHolderPtr;
	typedef FunctionHolderPtr HolderType;

public:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8);
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), dynamic_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), dynamic_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor(){};

	~functor(){};

	functor(const functor& func)
	{
		m_hs = func.m_hs;
	} 

	functor(FunctionType func)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassStub, FunctionType>(func));
	} 

	template <typename ClassPointerType, typename MemFun>
	functor(ClassPointerType pObj, MemFun mFun)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassPointerType, MemFun>(pObj, mFun));
	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}
		m_hs = functor_.m_hs;
		return *this;
	}

	void clear()
	{
		m_hs = FunctionHolderPtr(0);
	}
	
	bool callable() const
	{
        if (m_hs == 0)
        {
            return false;
        }
		return m_hs->callable();
	}
	
	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) const
	{
        ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (*m_hs)(t0, t1, t2, t3, t4, t5, t6, t7, t8);
	}

private:

	HolderType  m_hs;
};


/*
	functor for static member function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7, t8
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), static_bind, ClassType>
{
private:
	typedef Ret(ClassType::*MemberFunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8);
	typedef typename traits::type_traits<ClassType>::pointer_type ClassPoinerType;

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), static_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), static_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor():pObj_(0), func_(0){};
	~functor(){};

	functor(ClassPoinerType pObj, MemberFunctionType mFun)
		:pObj_(pObj), func_(mFun)
	{}

	functor(const functor& functor_)
		:pObj_(functor_.pObj_), func_(functor_.func_)
	{

	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		pObj_ = functor_.pObj_;
		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		pObj_ = 0;
	}

	bool callable() const
	{
		return pObj_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (pObj_->*func_)(t0, t1, t2, t3, t4, t5, t6, t7, t8);
	}

private:
	ClassPoinerType pObj_;
	MemberFunctionType func_;
};


/*
	functor for static function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7, t8
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), static_bind, ClassStub>
{
private:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8);

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), static_bind, ClassStub> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), static_bind, ClassStub> functor_list_type;
	typedef Ret return_type;

	functor():func_(0){};
	~functor(){};

	functor(const functor& functor_)
		:func_(functor_.func_)
	{

	}

	functor(FunctionType mFun)
		:func_(mFun)
	{}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		func_ = 0;
	}

	bool callable() const
	{
		return func_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (func_)(t0, t1, t2, t3, t4, t5, t6, t7, t8);
	}

private:
	FunctionType func_;
};



/*
	functor_list
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7, t8
*/
template<typename BindType, typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8 >
class functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType, ClassType>
{
public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType, ClassType> functor_list_type;
	typedef Ret return_type;
	   
	functor_list()
    {
    }

	~functor_list()
    {
    }
	   
	functor_list(const functor_list& del)
		:m_hs(del.m_hs)
	{
	}

	functor_list(const functor_type& del)
	{
		m_hs.push_back(del);
	}

	functor_list& operator+(const functor_list& rhs)
	{
		m_hs.insert(m_hs.end(), rhs.m_hs.begin(), rhs.m_hs.end());
		return *this;
	}

	functor_list& operator+(const functor_type& rhs)
	{
		m_hs.push_back(rhs);
		return *this;
	}

	functor_list& operator+=(const functor_list& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	functor_list& operator+=(const functor_type& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	_uint32_ size() const
	{
		return m_hs.size();
	}

	void clear()
	{
		m_hs.clear();
	}

	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8) const
	{
		for (HolderIterator it = m_hs.begin();
			it != m_hs.end() - 1;
			++it)
		{
			(*it)(t0, t1, t2, t3, t4, t5, t6, t7, t8);
		}
		return (*(m_hs.end() - 1))(t0, t1, t2, t3, t4, t5, t6, t7, t8);
	}


private:
	typedef std::vector<functor_type> HolderType;
	typedef typename HolderType::const_iterator  HolderIterator;

	HolderType  m_hs;
};


/*
	functor_type
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8
*/
template<typename BindType, typename RtVal, typename ClassType , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
struct functor_type<RtVal (ClassType::*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType, ClassType> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
struct functor_type<RtVal (*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType, ClassStub> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8), BindType, ClassStub> list_type;
};

/*********************************************************/





/*********************************************************/
/*
	functor for dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7, t8, t9
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), dynamic_bind, ClassType>
{
private:
	struct FunctionHolderBase
	{
		virtual Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) const = 0;
		virtual ~FunctionHolderBase(){};
        virtual bool callable() const = 0;
	};


	template<typename ClassPointerType, typename Function>
	struct FunctionHolder : public FunctionHolderBase
	{
		ClassPointerType pObj_;
		Function func_;

		FunctionHolder(ClassPointerType pObj, const Function& func)
			: pObj_(pObj), func_(func){}

        bool callable() const
        {
            return bool(pObj_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) const
		{
			return (pObj_->*func_)(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
		}
	};

	template<typename Function>
	struct FunctionHolder<ClassStub, Function> : public FunctionHolderBase
	{
		Function func_;

		FunctionHolder(Function func):func_(func){}

        bool callable() const
        {
            return bool(func_);
        }

		Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) const
		{
			return (func_)(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
		}
	};

	typedef acapella::shared_ptr<const FunctionHolderBase> FunctionHolderPtr;
	typedef FunctionHolderPtr HolderType;

public:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9);
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), dynamic_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), dynamic_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor(){};

	~functor(){};

	functor(const functor& func)
	{
		m_hs = func.m_hs;
	} 

	functor(FunctionType func)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassStub, FunctionType>(func));
	} 

	template <typename ClassPointerType, typename MemFun>
	functor(ClassPointerType pObj, MemFun mFun)
	{
		m_hs = FunctionHolderPtr(
			new FunctionHolder<ClassPointerType, MemFun>(pObj, mFun));
	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}
		m_hs = functor_.m_hs;
		return *this;
	}

	void clear()
	{
		m_hs = FunctionHolderPtr(0);
	}
	
	bool callable() const
	{
        if (m_hs == 0)
        {
            return false;
        }
		return m_hs->callable();
	}
	
	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) const
	{
        ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (*m_hs)(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
	}

private:

	HolderType  m_hs;
};


/*
	functor for static member function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7, t8, t9
*/
template<typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), static_bind, ClassType>
{
private:
	typedef Ret(ClassType::*MemberFunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9);
	typedef typename traits::type_traits<ClassType>::pointer_type ClassPoinerType;

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), static_bind, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), static_bind, ClassType> functor_list_type;
	typedef Ret return_type;

	functor():pObj_(0), func_(0){};
	~functor(){};

	functor(ClassPoinerType pObj, MemberFunctionType mFun)
		:pObj_(pObj), func_(mFun)
	{}

	functor(const functor& functor_)
		:pObj_(functor_.pObj_), func_(functor_.func_)
	{

	}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		pObj_ = functor_.pObj_;
		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		pObj_ = 0;
	}

	bool callable() const
	{
		return pObj_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (pObj_->*func_)(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
	}

private:
	ClassPoinerType pObj_;
	MemberFunctionType func_;
};


/*
	functor for static function binding
	this should be faster than dynamic binding
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7, t8, t9
*/
template<typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9 >
class functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), static_bind, ClassStub>
{
private:
	typedef Ret(*FunctionType)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9);

public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), static_bind, ClassStub> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), static_bind, ClassStub> functor_list_type;
	typedef Ret return_type;

	functor():func_(0){};
	~functor(){};

	functor(const functor& functor_)
		:func_(functor_.func_)
	{

	}

	functor(FunctionType mFun)
		:func_(mFun)
	{}

	functor& operator=(const functor& functor_)
	{
		if (this == &functor_)
		{
			return *this;
		}

		func_ = functor_.func_;
		return *this;
	}


	void clear()
	{
		func_ = 0;
	}

	bool callable() const
	{
		return func_ != 0;
	}

	inline Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) const
	{
		ACAPELLA_ASSERT(callable(), "functor is not callable");
		return (func_)(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
	}

private:
	FunctionType func_;
};



/*
	functor_list
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
	FUNCTION_ARGS = T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9
	FUNCTION_PARA = t0, t1, t2, t3, t4, t5, t6, t7, t8, t9
*/
template<typename BindType, typename ClassType, typename Ret , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9 >
class functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType, ClassType>
{
public:
	typedef functor<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType, ClassType> functor_type;
	typedef functor_list<Ret(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType, ClassType> functor_list_type;
	typedef Ret return_type;
	   
	functor_list()
    {
    }

	~functor_list()
    {
    }
	   
	functor_list(const functor_list& del)
		:m_hs(del.m_hs)
	{
	}

	functor_list(const functor_type& del)
	{
		m_hs.push_back(del);
	}

	functor_list& operator+(const functor_list& rhs)
	{
		m_hs.insert(m_hs.end(), rhs.m_hs.begin(), rhs.m_hs.end());
		return *this;
	}

	functor_list& operator+(const functor_type& rhs)
	{
		m_hs.push_back(rhs);
		return *this;
	}

	functor_list& operator+=(const functor_list& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	functor_list& operator+=(const functor_type& rhs)
	{
		*this = *this + rhs;
		return *this;
	}

	_uint32_ size() const
	{
		return m_hs.size();
	}

	void clear()
	{
		m_hs.clear();
	}

	Ret operator()(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9) const
	{
		for (HolderIterator it = m_hs.begin();
			it != m_hs.end() - 1;
			++it)
		{
			(*it)(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
		}
		return (*(m_hs.end() - 1))(t0, t1, t2, t3, t4, t5, t6, t7, t8, t9);
	}


private:
	typedef std::vector<functor_type> HolderType;
	typedef typename HolderType::const_iterator  HolderIterator;

	HolderType  m_hs;
};


/*
	functor_type
	TEMPLATE_ARGS = , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9
*/
template<typename BindType, typename RtVal, typename ClassType , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
struct functor_type<RtVal (ClassType::*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType, ClassType> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType, ClassType> list_type;
};

template<typename BindType, typename RtVal , typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
struct functor_type<RtVal (*)(T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType>
{
	typedef functor<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType, ClassStub> type;
	typedef functor_list<RtVal (T0 t0, T1 t1, T2 t2, T3 t3, T4 t4, T5 t5, T6 t6, T7 t7, T8 t8, T9 t9), BindType, ClassStub> list_type;
};

/*********************************************************/





